package com.tao.mytestdd.datagrama

import com.tao.mytestdd.datagrama.DatagramService.DatagramCall

/**
 * reate by tao on{DATE}
 */
object DataGramClient {
    @JvmStatic
    fun main(args: Array<String>) {
        val service = DatagramService()
        service.call =  MyCall(service)
        service.init(6667)
        
    }
    val udpSendManager = UDPSendManager("192.168.0.37", 6667)

    internal class MyCall(var service: DatagramService) : DatagramCall {

        override fun onClose() {
            System.err.println("onClose")
        }

        override fun onError(msg: String, exception: Exception?) {
            System.err.println("onError " + msg + " " + exception.toString())
        }

        override fun onReceiver(msg: DataEntity<String?>?) {
            System.err.println("onReceiver ${msg?.obj}")
            Thread.sleep(100)
            udpSendManager.sendMag(UDPSendManager.createMsg( 699000) ,"server")
        }
 
        override fun onSend(msg: String) {
            System.err.println("onSend $msg")
        }

        override fun onOpen() {
            System.err.println("onOpen ")
            udpSendManager.registerClient( "server" ,"192.168.0.104",6665)
            udpSendManager.sendMag("你好服务端——我是客户端","server")
        }
    }


}